package cn.znzz.cjm.interceptor;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class UserInfoFeignInterceptor implements RequestInterceptor {
    private final String url = "http://localhost:1040/oauth/token?client_id=system&client_secret=1&grant_type=client_credentials&redirect_uri=http://www.baidu.com";
    @Override
    public void apply(RequestTemplate requestTemplate) {
        String data = HttpUtil.get(url);
        Map<String,Object> map = JSON.parseObject(data, Map.class);
        String token = map.get("access_token").toString();
        System.err.println(token);
        requestTemplate.header("Authorization","bearer  "+token);
    }
}